package com.liao.excel.service.impl;

import com.liao.excel.Cat;
import com.liao.excel.strategy.ScreenValueStrategy;
import com.liao.excel.strategy.WriteStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@Service
public class CatServiceImpl {

    @Autowired
    private WriteStrategy writeStrategy;

    public void writeProMat(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Cat cat) throws Exception {
        WriteStrategy.setHttpServletResponse(httpServletResponse, "ProMatFile.xlsx");
        Cat cat1 = new Cat().setAddress("北半球").setAge(1).setColor("黄色")
                .setCountry("中国").setName("小黄猫").setType("田园猫");
        Cat cat2 = new Cat().setAddress("北半球").setAge(1).setColor("黄色")
                .setCountry("英国").setName("小黑猫").setType("田园猫");
        List<Cat> list = new ArrayList<>();
        list.add(cat1);
        list.add(cat2);
        list.add(cat1);
        list.add(cat1);
        writeStrategy.write("物料报表", Cat.class, list, httpServletResponse,
                new ScreenValueStrategy(list, new Integer[]{1, 4, 6}, new Integer[]{3, 5, 18}, 3)
        );
    }
}
